﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using FastReport;

using MINERP.BLL.FactoryTech;
using MINERP.FactoryTech.IView;
using MINERP.MODEL.FactoryTech;
using System.Data;
using System.Xml;
using System.Windows.Forms;
using MINERP.BLL.QC;

namespace MINERP.FactoryTech.Presenter
{
   
    public class MainPresenter
    {
        private IMainView _iView;
        private FactoryTechBLL _bll;


        public MainPresenter(IMainView iView)
        {
            _iView = iView;
            _bll  = new FactoryTechBLL();
        }
        /// <summary>
        /// 通过产品ID获得该产品的当前流程ID
        /// </summary>
        /// <param name="productId"></param>
        /// <returns>0 产品不存在，-1 产品无流程或者流程已完成,-2 该产品当前流程不在相册厂工艺流程中</returns>
        public int GetCurrentTechIdByOrderProductId(string productcode,out string msg)
        {
            return _bll.GetCurrentTechIdByOrderProductId(productcode, out msg);
        }

        /// <summary>
        /// 完成流程
        /// </summary>
        /// <param name="techId"></param>
        /// <param name="userId"></param>
        /// <param name="orderproductId"></param>
        /// <returns></returns>
        public bool CompleteTech(int techId, int userId, string  orderproductcode,Dictionary<int,string> oprates)
        {
            return _bll.CompleteTech(techId, userId, orderproductcode, oprates);
        }

        /// <summary>
        /// 接收任务
        /// </summary>
        /// <param name="techId"></param>
        /// <param name="userId"></param>
        /// <param name="orderproductcode"></param>
        /// <returns>0 接收成功，-1 接收失败</returns>
        public int ReceiveTask(int techId,int userId,string orderproductcode)
        {
            return _bll.ReceiveTask(techId, userId, orderproductcode);
        }
        /// <summary>
        /// 显示任务
        /// </summary>
        /// <param name="userId"></param>
        public void ShowTask(int userId)
        {
            List<TaskInfo> TaskList = _bll.GetListTask(userId);
            _iView.ShowTasks(TaskList);
        }

        public void ShowTask(List<int> Task) 
        {
            List<TaskInfo> TaskList = _bll.GetListTask(Task);
            _iView.ShowTasks(TaskList);
        }
        /// <summary>
        /// 获根据产品Id获得任务
        /// </summary>
        /// <param name="orderproductId"></param>
        /// <returns></returns>
        public TaskInfo GetTaskInfo(string orderproductCode)
        {
            return _bll.GetTask(orderproductCode);
        }

        public void PrintBarcode()
        {
            Report report = new Report();
            DataTable table = _bll.GetPrintInfo(_iView.CurrBarCode);
            XmlDocument doc = new XmlDocument();
            table.WriteXml(@"C:\Windows\xmldata\barDT.xml", XmlWriteMode.WriteSchema);
            report.Load(Application.StartupPath + "\\FactoryBarCode.frx");
            report.PrintSettings.ShowDialog = false;
            //report.Show();
            report.Print();
        }

        QCBLL _qcbll = new QCBLL();
        internal List<MINERP.BLL.QC.QCBLL.CheckPhoto> GetPhotoList(string productCode)
        {
            List<MINERP.BLL.QC.QCBLL.CheckPhoto> photos = _qcbll.GetPhotosByOrderProductCode(productCode);
            return photos;
        }

        internal string GetProductCodeByPhotoID(int photoID)
        {
            return _bll.GetProductCodeByPhotoID(photoID);
        }
    }
}
